package com.example.common.api;

public enum ResultCode implements IResultCode{

    SUCCESS(200, "请求成功"),
    FAILED(300, "请求失败"),

    FEIGN_ERROR(500, "服务器异常"),

    CREATE_USER_ERROR(300, "创建账户失败"),

    UPDATE_USER_ERROR(300, "修改账户失败"),

    MOBILE_EXIST(300, "该手机号已经注册为用户，请直接登录"),

    LOGIN_ERROR(300, "登录失败"),

    ACCOUNT_OR_PASSWORD_ERROR(300, "账号或密码错误"),

    CREATE_GOODS_CLASSIFY_ERROR(300, "创建商品分类失败"),

    GET_GOODS_CLASSIFY_EMPTY(200, "没有获取到商品分类数据"),

    CREATE_GOODS_ERROR(300, "创建商品失败"),

    VALIDATE_FAILED(404, "参数检验失败"),

    UNAUTHORIZED(401, "暂未登录或token已过期"),

    FORBIDDEN(403, "没有相关权限"),

    ERROR_TOKEN_PREFIX(205, "token不是已Bearer开头"),

    TOKEN_INVALID_OR_EXPIRED(206, "无效的Token或已过期"),

    TOKEN_MISSION(208, "Token缺失"),

    TOKEN_SIGNATURE_INVALID(209, "无效的签名"),

    ERROR_SAVE_REDIS(201, "redis存储错误"),

    ERROR_GET_REDIS(201, "redis取值错误"),

    UNKNOWN_ERROR(410, "未知错误"),

    CREATE_ROLE_ERROR(300, "创建角色失败"),

    UPDATE_ROLE_STATUS_ERROR(300, "修改角色状态失败"),

    DISABLE_ROLE_ERROR(300, "该角色下有用户存在，不能禁用"),

    CREATE_ADDRESS_ERROR(300, "创建用户地址失败"),

    UPDATE_ADDRESS_ERROR(300, "修改用户地址失败"),
    ;

    private int code;
    private String message;

    ResultCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public static ResultCode getResultByCode(int code){
        for (ResultCode result: values()){
            if (result.getCode() == code){
                return result;
            }
        }

        return null;
    }
}
